package com.xinghanlaser.applet.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import com.xinghanlaser.applet.base.common.exception.ServiceException;

/**
 * <p>
 *
 * <p>
 *
 * @author: mftuo 陀铭峰
 * @since: 2024/5/27 17:53
 */
public class AESDecryptionUtil {
    private static final String key = "1234567812345678";

    private static final String iv = "1234567812345678";

    private static final AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());

    public static String encrypt(String text){
        if(StrUtil.isBlank(text)){
            throw new ServiceException("加密字符串不能为空");
        }

        return aes.encryptBase64(text);
    }

    public static String decrypt(String text){
        if(StrUtil.isBlank(text)){
            throw new ServiceException("解密字符串不能为空");
        }

        return aes.decryptStr(text);
    }
}
